package cn.tutu.blockchain.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.tutu.blockchain.common.MsgObj;
import cn.tutu.blockchain.contact.entity.Contact;
import cn.tutu.blockchain.contact.service.ContactService;

@RestController
@RequestMapping("/contact")
public class ContactController {

	private static Logger LOGGER = LoggerFactory.getLogger(ContactController.class);

	@Autowired
	private ContactService contactService;

	@RequestMapping("/create")
	public MsgObj create(Contact contact) {
		LOGGER.info("添加联系人:targetUserId[{}],sourceUserId[{}]", contact.getTargetUserId(), contact.getSourceUserId());
		contactService.create(contact);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/getGrid")
	public MsgObj getAddrList(String sourceUserId) {
		List<Contact> contactList = contactService.getContact(sourceUserId);
		MsgObj msg = MsgObj.buildSuccessObj(contactList);
		return msg;
	}

}
